package org.jetnuke.common;

import org.apache.velocity.VelocityContext;

public class ValidationError {
	final public static int REQUIRED = 1;

	final public static int MINLENGTH = 2;

	final public static int MAXLENGTH = 3;

	final public static int NOT_VALID = 99;

	VelocityContext vc;

	String label;

	public ValidationError(String paramName, int errorCode, String label,
			VelocityContext vc) {
		this.paramName = paramName;
		this.label = label;
		this.errorCode = errorCode;
		this.vc = vc;
	}

	String paramName;

	int errorCode;

	public int getErrorCode() {
		return errorCode;
	}

	public void setErrorCode(int errorCode) {
		this.errorCode = errorCode;
	}

	public String getParamName() {
		return paramName;
	}

	public void setParamName(String paramName) {
		this.paramName = paramName;
	}

	public String getLabel() {
		if (label != null)
			return (String) vc.get(label);
		else
			return paramName;
	}

	public String getDescription() {
		if (errorCode == REQUIRED)
			return (String) vc.get("_REQUIRED");
		else if (errorCode == MINLENGTH)
			return (String) vc.get("_MIN_LENGTH");
		else if (errorCode == MAXLENGTH)
			return (String) vc.get("_MAX_LENGTH");
		else if (errorCode == NOT_VALID)
			return (String) vc.get("_NOT_VALID");
		return "";
	};
}
